/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.locadora.classes;

import javax.swing.JOptionPane;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author Welinton
 */
public class Persistencia {

    public static SessionFactory sfac = new Configuration().configure().buildSessionFactory();
    public static Session se;
    public static Transaction tx;

    public static void salvarObjeto(Object o) {
        se = sfac.openSession();
        tx = se.beginTransaction();
        se.save(o);
        tx.commit();
        se.clear();
    }

    public static void deletarObjeto(Object o) {
        se = sfac.openSession();
        tx = se.beginTransaction();
        se.delete(o);
        tx.commit();
        se.close();
    }

    public static void alteraObjeto(Object o) {
        se = sfac.openSession();
        tx = se.beginTransaction();
        se.update(o);
        tx.commit();
        se.close();
    }

    public static void mensagem(String objeto, String messagem) {
        JOptionPane.showMessageDialog(null, objeto + ".:" + messagem);
    }
}
